package com.financing.task.user;
import java.util.List;

import org.apache.log4j.Logger;

import com.financing.model.user.User;
import com.financing.service.invest.CouponService;
import com.jfinal.aop.Before;
import com.jfinal.plugin.activerecord.tx.Tx;

/**
 * 生日提醒任务
 * @author 无处不在的二叔
 */
public class BirthdayNotifyTask implements Runnable{
	private CouponService coupon = new CouponService();	
    private static final Logger logger = Logger.getLogger(BirthdayNotifyTask.class);
    
	@Override 
	@Before(Tx.class)
	public void run() {
		// 查找生日用户（提前一天提醒）
		 List<User> boys = User.me.find("select real_name,birthday from user where date_format( birthday, '%m%d' ) = date_format( date_add( now( ) , INTERVAL -1 DAY ) , '%m%d' ) LIMIT 0 , 500");
		 for(User b : boys){
			 
			 // 打印日志
			logger.info("^(*￣(oo)￣)^ 祝用户"+b.getRealName()+"生日快乐，日期是"+b.getBirthday()+"！");
			
			// 获取优惠券
			coupon.available(b.getId(), "birthday");

			 // 客服提醒
			
		 }
	}
}
